home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / util / libs / graphics3d.lha / src / library / graphics3Dli.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-12  |  6.4 KB  |  214 lines

  1. /*
  2. **      $VER: LibInit.c 37.16 (23.8.97)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <exec/execbase.h>
  14. #include <exec/resident.h>
  15. #include <exec/initializers.h>
  16.  
  17. #include <proto/exec.h>
  18.  
  19. #include "graphics3Dbase.h"
  20.  
  21. ULONG L_OpenLibs(void);
  22. void  L_CloseLibs(void);
  23.  
  24. extern struct Graphics3DBase *Graphics3DBase;
  25.  
  26.  
  27. struct ExecBase      *SysBase              = NULL;
  28. struct IntuitionBase *IntuitionBase        = NULL;
  29. struct GfxBase       *GfxBase               = NULL;
  30. struct LayersBase    *LayersBase           = NULL;
  31. struct MathIEEEBase  *MathIeeeDoubBasBase  = NULL;
  32. struct MathIEEEBase  *MathIeeeSingBasBase  = NULL;
  33. struct DOSBase         *DOSBase              = NULL;
  34.  
  35. #define VERSION  15
  36. #define REVISION 10 
  37.  
  38. char ExLibName [] = "graphics3D.library";
  39. char ExLibID   [] = "graphics3D 15.10 (10.05.99)";
  40. char Copyright [] = "(C)opyright 1996-99 by Patrizio Biancalani & Andreas R. Kleinert . All rights reserved.";
  41.  
  42.  
  43. /* -------------------------------------------------------------------------
  44.  ! ROMTag and Library inilitalization structure:
  45.  !
  46.  ! Below you find the ROMTag, which is the most important "magic" part 
  47.  ! of a library (as for any other resident module). You should not need 
  48.  ! to modify any of the structures directly, since all the data is 
  49.  ! referenced from constants from somewhere else.
  50.  !
  51.  ! You may place the ROMTag directly after the LibStart (-> StartUp.c) 
  52.  ! function as well.
  53.  !
  54.  ! Note, that the data initialization structure may be somewhat redundantit's
  55.  ! for demonstration purposes.
  56.  !
  57.  ! EndResident can be placed somewhere else - but it must follow the ROMTag 
  58.  ! and it must not be placed in a different SECTION.
  59.  ------------------------------------------------------------------------ */
  60.  
  61. extern ULONG InitTab[];
  62. extern APTR EndResident; /* below */
  63.  
  64. struct Resident ROMTag =     /* do not change */
  65. {
  66.  RTC_MATCHWORD,
  67.  &ROMTag,
  68.  &EndResident,
  69.  RTF_AUTOINIT,
  70.  VERSION,
  71.  NT_LIBRARY,
  72.  0,
  73.  &ExLibName[0],
  74.  &ExLibID[0],
  75.  &InitTab[0]
  76. };
  77.  
  78. APTR EndResident;
  79.  
  80. struct MyDataInit                      /* do not change */
  81. {
  82.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  83.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  84.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  85.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  86.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  87.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  88.  ULONG ENDMARK;
  89. } DataTab =
  90. #ifdef VBCC
  91. {
  92.     0xe000,8,NT_LIBRARY, 
  93.     0x0080,10,(ULONG) &ExLibName[0], 
  94.     0xe000,LIBF_SUMUSED|LIBF_CHANGED, 
  95.     0xd000,20,VERSION, 
  96.     0xd000,22,REVISION, 
  97.     0x80,24,(ULONG) &ExLibID[0], 
  98.     (ULONG) 0
  99. };
  100. #else
  101. {
  102.  INITBYTE(OFFSET1(Node,         ln_Type),      NT_LIBRARY),
  103.  0x80, (UBYTE) OFFSET1(Node,    ln_Name),      (ULONG) &ExLibName[0],
  104.  INITBYTE(OFFSET1(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  105.  INITWORD(OFFSET1(Library,      lib_Version),  VERSION),
  106.  INITWORD(OFFSET1(Library,      lib_Revision), REVISION),
  107.  0x80, (UBYTE) OFFSET1(Library, lib_IdString), (ULONG) &ExLibID[0],
  108.  (ULONG) 0
  109. };
  110. #endif
  111.  
  112. /*--------------------------------------------------------------------------
  113.  ! L_OpenLibs:
  114.  !
  115.  ! Since this one is called by InitLib, libraries not shareable between 
  116.  ! Processes or libraries messing with RamLib (deadlock and crash) may not 
  117.  ! be opened here.
  118.  !
  119.  ! You may bypass this by calling this function fromout LibOpen, but then 
  120.  ! you will have to a) protect it by a semaphore and b) make sure, that 
  121.  ! libraries are only opened once (when using globa library bases).
  122.  ------------------------------------------------------------------------ */
  123.  
  124. ULONG L_OpenLibs(void)
  125. {
  126.  SysBase = (*((struct ExecBase **) 4));
  127.  
  128.  IntuitionBase =
  129.     (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  130.  if(!IntuitionBase) return(FALSE);
  131.  
  132.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  133.  if(!GfxBase) 
  134.     {
  135.     CloseLibrary(IntuitionBase);
  136.     return(FALSE);
  137.     }
  138.  
  139.  LayersBase = (struct LayersBase *) OpenLibrary("layers.library", 37);
  140.  if(!LayersBase) 
  141.     {
  142.     CloseLibrary(IntuitionBase);
  143.     CloseLibrary(GfxBase);
  144.     return(FALSE);
  145.     }
  146.  
  147.  MathIeeeSingBasBase=
  148.     (struct MathIeeeSingBasBase *)
  149.     OpenLibrary("mathieeesingbas.library",37);
  150.  if(!MathIeeeSingBasBase) 
  151.     {
  152.     CloseLibrary(IntuitionBase);
  153.     CloseLibrary(GfxBase);
  154.     CloseLibrary(LayersBase);
  155.     return(FALSE);
  156.     }
  157.  
  158.  MathIeeeDoubBasBase=
  159.     (struct MathIeeeDoubBasBase *)
  160.     OpenLibrary("mathieeedoubbas.library",37);
  161.  if(!MathIeeeDoubBasBase) 
  162.     {
  163.     CloseLibrary(IntuitionBase);
  164.     CloseLibrary(GfxBase);
  165.     CloseLibrary(LayersBase);
  166.     CloseLibrary(MathIeeeSingBasBase);
  167.     return(FALSE);
  168.     }
  169.  DOSBase = (struct DOSBase *) OpenLibrary("dos.library", 37);
  170.  if(!DOSBase) 
  171.     {
  172.     CloseLibrary(IntuitionBase);
  173.     CloseLibrary(GfxBase);
  174.     CloseLibrary(LayersBase);
  175.     CloseLibrary(MathIeeeSingBasBase);
  176.     CloseLibrary(MathIeeeDoubBasBase);
  177.     return(FALSE);
  178.     }
  179.  
  180.  Graphics3DBase->exb_SysBase       = SysBase;
  181.  
  182.  Graphics3DBase->exb_IntuitionBase        = IntuitionBase;
  183.  Graphics3DBase->exb_GfxBase              = GfxBase;
  184.  Graphics3DBase->exb_LayersBase           = LayersBase;
  185.  Graphics3DBase->exb_MathIeeeDoubBasBase  = MathIeeeDoubBasBase;
  186.  Graphics3DBase->exb_MathIeeeSingBasBase  = MathIeeeSingBasBase;
  187.  Graphics3DBase->exb_DOSBase       = DOSBase;
  188.  
  189.  return(TRUE);
  190. }
  191.  
  192. /* -------------------------------------------------------------------------
  193.  ! L_CloseLibs:
  194.  !
  195.  ! This one by default is called by ExpungeLib, which only can take place 
  196.  ! once and thus per definition is single-threaded.
  197.  !
  198.  ! When calling this fromout LibClose instead, you will have to protect it 
  199.  ! by a semaphore, since you don't know whether a given CloseLibrary(foobase)
  200.  ! may cause a Wait().
  201.  ! Additionally, there should be protection, that a library won't be closed 
  202.  ! twice.
  203.  ------------------------------------------------------------------------ */
  204.  
  205. void L_CloseLibs(void)
  206. {
  207.  if(DOSBase) CloseLibrary((struct Library *) DOSBase);
  208.  if(MathIeeeDoubBasBase) CloseLibrary((struct Library *)MathIeeeDoubBasBase);
  209.  if(MathIeeeSingBasBase) CloseLibrary((struct Library *)MathIeeeSingBasBase);
  210.  if(LayersBase) CloseLibrary((struct Library *) LayersBase);
  211.  if(GfxBase)       CloseLibrary((struct Library *) GfxBase);
  212.  if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  213. }
  214.